function heightLight(id){
    $(".nav-list").each(function(){
        var $this = $(this);
        var li_id = $this.data("id");
        if(li_id == id){
            $this.find('.nav-icon').addClass("nav-icon"+ li_id +"-on");
            $this.find('.nav-tab-label').addClass("nav-tab-label-on");
        }
    });
}

function GetQueryString(name)
{
    var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if(r!=null)return  unescape(r[2]); return null;
}

/**
 * 乘法函数
 */
function accMul(arg1, arg2) {
    var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
    try {
        m += s1.split(".")[1].length;
    }
    catch (e) {
    }
    try {
        m += s2.split(".")[1].length;
    }
    catch (e) {
    }
    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
}
/**
 * 除法函数
 */

function accDiv(arg1, arg2) {
    var t1 = 0, t2 = 0, r1, r2;
    try {
        t1 = arg1.toString().split(".")[1].length;
    }
    catch (e) {
    }
    try {
        t2 = arg2.toString().split(".")[1].length;
    }
    catch (e) {
    }
    with (Math) {
        r1 = Number(arg1.toString().replace(".", ""));
        r2 = Number(arg2.toString().replace(".", ""));
        return (r1 / r2) * pow(10, t2 - t1);
    }
}
/**
 * 加法函数
 */
function accAdd(arg1, arg2) {
    var r1, r2, m;
    try {
      r1 = arg1.toString().split(".")[1].length;
    }
    catch (e) {
      r1 = 0;
    }
    try {
      r2 = arg2.toString().split(".")[1].length;
    }
    catch (e) {
      r2 = 0;
    }
    m = Math.pow(10, Math.max(r1, r2));
    return (arg1 * m + arg2 * m) / m;
}
/**
 * 减法函数
 */
function Subtr(arg1, arg2) {
    var r1, r2, m, n;
    try {
      r1 = arg1.toString().split(".")[1].length;
    }
    catch (e) {
      r1 = 0;
    }
    try {
      r2 = arg2.toString().split(".")[1].length;
    }
    catch (e) {
      r2 = 0;
    }
    m = Math.pow(10, Math.max(r1, r2));
    //last modify by deeka
    //动态控制精度长度
    n = (r1 >= r2) ? r1 : r2;
    return ((arg1 * m - arg2 * m) / m).toFixed(n);
}

/**
 *
 * 序列化对象
 *
 * return param
 *
 */
$.fn.serializeObject = function()
{
    var obj = {};
    var a = this.serializeArray();
    $.each(a, function() {
        if (obj[this.name] !== undefined) {
            if (!obj[this.name].push) {
                obj[this.name] = [obj[this.name]];
            }
            obj[this.name].push(this.value || '');
        } else {
            obj[this.name] = this.value || '';
        }
    });
    return obj;
};

/**
 * 锁定编辑器中光标的位置
 *
 * @param html text
 *
 */

function insertHtmlAtCaret(html) {
    var sel, range;
    if (window.getSelection) {
        // IE9 and non-IE
        sel = window.getSelection();
        if (sel.getRangeAt && sel.rangeCount) {
            range = sel.getRangeAt(0);
            range.deleteContents();
            // Range.createContextualFragment() would be useful here but is
            // non-standard and not supported in all browsers (IE9, for one)
            var el = document.createElement("div");
            el.innerHTML = html;
            console.log(el.innerHTML);
            var frag = document.createDocumentFragment(), node, lastNode;
            while ((node = el.firstChild)) {
                lastNode = frag.appendChild(node);
            }
            range.insertNode(frag);
            // Preserve the selection
            if (lastNode) {
                range = range.cloneRange();
                range.setStartAfter(lastNode);
                range.collapse(true);
                sel.removeAllRanges();
                sel.addRange(range);
            }
        }
    } else if (document.selection && document.selection.type != "Control") {
        // IE < 9
        document.selection.createRange().pasteHTML(html);
    }
}


var selection = '';
var range = '';

function _insertimg(str)
{
    selection = window.getSelection ? window.getSelection() : document.selection;
    range = selection.createRange ? selection.createRange() : selection.getRangeAt(0);

    if (!window.getSelection)
    {
        document.getElementById('editor').focus();
        selection= window.getSelection ? window.getSelection() : document.selection;
        range= selection.createRange ? selection.createRange() : selection.getRangeAt(0);
        range.pasteHTML(str);
        range.collapse(false);
        range.select();
    }
    else
    {
        document.getElementById('editor').focus();
        range.collapse(false);
        var hasR = range.createContextualFragment(str);
        var hasR_lastChild = hasR.lastChild;
        while (hasR_lastChild && hasR_lastChild.nodeName.toLowerCase() == "br" && hasR_lastChild.previousSibling && hasR_lastChild.previousSibling.nodeName.toLowerCase() == "br") {
            var e = hasR_lastChild;
            hasR_lastChild = hasR_lastChild.previousSibling;
            hasR.removeChild(e)
        }
        range.insertNode(hasR);
        if (hasR_lastChild) {
            range.setEndAfter(hasR_lastChild);
            range.setStartAfter(hasR_lastChild)
        }
        selection.removeAllRanges();
        selection.addRange(range)
    }
}

//自定义提示框
function alertData(text)
{
    $('.custom-alert').text(text).show(1).delay(1000).hide(1);
}


/**
 *
 *  光标移动到尾部
 *
 */

//定位input、textarea
function po_Last(obj) {
    obj.focus();//解决ff不获取焦点无法定位问题
    if (window.getSelection) {//ie11 10 9 ff safari
        var max_Len=obj.value.length;//text字符数
        obj.setSelectionRange(max_Len, max_Len);
    }
    else if (document.selection) {//ie10 9 8 7 6 5
        var range = obj.createTextRange();//创建range
        range.collapse(false);//光标移至最后
        range.select();//避免产生空格
    }
}


//定位div(contenteditable = "true")
function po_Last_Div(obj) {
    if (window.getSelection) {//ie11 10 9 ff safari
        obj.focus(); //解决ff不获取焦点无法定位问题
        var range = window.getSelection();//创建range
        range.selectAllChildren(obj);//range 选择obj下所有子内容
        range.collapseToEnd();//光标移至最后
    }
    else if (document.selection) {//ie10 9 8 7 6 5
        var range = document.selection.createRange();//创建选择对象
        //var range = document.body.createTextRange();
        range.moveToElementText(obj);//range定位到obj
        range.collapse(false);//光标移至最后
        range.select();
    }
}

/**
 *
 * 上传图片
 *
 */

function uploadFile(url) {
    var _file = this;
    var request_val = '';

    var data = new FormData();
    data.append('request', _file.files[0]);

    $.ajax({
        url: url,
        type: 'POST',
        dataType: 'json',
        processData: false,
        contentType: false,
        async: false,
        data: data,
        success: function (photo) {

        }
    });

    return request_val;
}

/**
 *
 * 预览图片
 *
 */

function viewImage (Fid, Did, Class, style) {
    //预览图片
    var simpleFile = document.getElementById(Fid).files[0];
    var reader = new FileReader();
    // 将文件以二进制文件读入页面中
    reader.readAsBinaryString(simpleFile);
    reader.onload = function(f){
        var result = document.getElementById(Did);
        var src = "data:" + simpleFile.type + ";base64," + window.btoa(this.result);
        result.innerHTML = '<img src ="'+src+'" class="'+ Class +'" style="'+ style +'" />';
    }
}